import request from '../utils/request';
import qs from 'qs';

// let domain = "localhost:8080";
let domain = "http://47.95.246.31:8090/sms";

export const getRequest = (url, data) => {
    if(data) {
        return request({"url":domain + url, "method": "get", "params": data});
    }else {
        return request({"url":domain + url, "method": "get"});
    }
}

// 目前接受 x-www-form-urlencoded 和 json 格氏
export const postRequest = (url, data, headers) => {
    if(headers) {
        if(headers['Content-Type'] == "application/x-www-form-urlencoded") {
            return request({
                "url": domain + url,
                "headers": headers,
                "method": "POST",
                "data": qs.stringify(data)
            })
        }else {
            return request({
                "url": domain + url,
                "method": "POST",
                "data": data,
                withCredentials:true,
                "headers":headers
            }) 
        }
    } else {
        return request({
            "url": domain + url,
            "method": "POST",
            "data": data,
            withCredentials:true
        })
    }
}


